package com.gmadmin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gmadmin.entity.MessageNotice;
import com.gmadmin.entity.vo.MessageNoticeVo;
import com.gmadmin.exception.BaseException;
import com.gmadmin.mapper.MessageMapper;
import com.gmadmin.service.MessageNoticeService;
import com.gmadmin.utils.CollectionBeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zhangliang
 * @version 1.0
 * @date 2022/8/3 1:20
 */
@Service
public class MessageNoticeServiceImpl extends ServiceImpl<MessageMapper, MessageNotice> implements MessageNoticeService {


    @Transactional(rollbackFor = BaseException.class)
    @Override
    public List<MessageNoticeVo> findListByReceiveIdAndType(Long receiveId, Long type, Long state) {
        List<MessageNotice> messageNotices = baseMapper.findListByReceiveIdAndType(receiveId, type, state);
        // 系统全局通知，接收人为null的就是全局通知
        List<MessageNotice> sysMessageNotices = baseMapper.findListByReceiveIdAndType(null, type, state);
        messageNotices.addAll(sysMessageNotices);
        return CollectionBeanUtils.copyListProperties(messageNotices, MessageNoticeVo::new);
    }


}
